package cn.daniellee.plugin.ea.command;

import cn.daniellee.plugin.ea.ExplodeAlone;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

public class AloneCommand implements CommandExecutor {
	@Override
	public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
		if (commandSender.isOp() && strings.length > 0 && "reload".equalsIgnoreCase(strings[0])) {
			ExplodeAlone.getInstance().reloadConfig();
			ExplodeAlone.getInstance().loadConfig();
			commandSender.sendMessage((ExplodeAlone.getInstance().getPrefix() + ExplodeAlone.getInstance().getConfig().getString("message.reload-success", "&eConfiguration reload successfully.")).replace("&", "§"));
		} else sendHelp(commandSender);
		return true;
	}

	private void sendHelp(CommandSender commandSender) {
		commandSender.sendMessage(("&m&6---&m&a--------&3 : " + ExplodeAlone.getInstance().getConfig().getString("prompt-prefix", "&6ExplodeAlone") + "&3 : &m&a--------&m&6---").replace("&", "§"));

		String reloadText = ExplodeAlone.getInstance().getConfig().getString("help.reload-help", "&eReload the plugin configuration file.").replace("&", "§");
		TextComponent reloadHelp = new TextComponent("/ea reload  " + reloadText);
		reloadHelp.setColor(ChatColor.GRAY);
		reloadHelp.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/ea reload"));
		reloadHelp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(reloadText).color(ChatColor.BLUE).create()));
		commandSender.spigot().sendMessage(reloadHelp);
	}

}
